package com.bc.web.controller.admin;

import com.fs.common.extend.FSController;
import com.fs.common.util.FSHttp;
import com.fs.common.util.FSJson;
import com.fs.common.util.FSMD5;

import java.util.HashMap;
import java.util.Map;

import com.bc.web.config.SystemConfig;
import com.bc.web.model.Org;
import com.bc.web.model.TradeOrder;
import com.jfinal.plugin.activerecord.Page;

public class UpdateAccountController extends FSController{
	
	public void search(){
		Page<TradeOrder> items = TradeOrder.dao.searchByBuDan(super.getSearchCondition());
		setPageResultToRequest("items", items);
		render("basedata/updateAccount.html");
	}
	
	
	
	public void queryOrderStatus(){
		String id = getPara("id");
		TradeOrder tradeOrder = TradeOrder.dao.findById(id);
		Org org = Org.dao.selectByOrgCode(tradeOrder.getOrgCode());
		String tradeSystemUrl = SystemConfig.config.get("trade_system_url") + "/route";
		Map<String,String> req = new HashMap<>();
		req.put("version", "V1.0");
		req.put("payType", "ower_query");
		req.put("orgCode", tradeOrder.getOrgCode());
		req.put("merchCode", tradeOrder.getMerchCode());
		req.put("merchOrderNo", tradeOrder.getMerchOrderNo());
		req.put("orderNo", tradeOrder.getOrderNo());
		req.put("sign", FSMD5.sortSign(req, org.getSafeKey()));
		try {
			String retJson = FSHttp.postJson(tradeSystemUrl, FSJson.toString(req));
			Map<String,String> resp = FSJson.toMap(retJson);
			if(resp.get("respCode").equals("00")){
				String origiOrderRespCode = resp.get("originalRespCode");
				if(origiOrderRespCode.equals("00")){
					renderSuccess("查询成功，订单状态成功");
				}else{
					renderSuccess("查询成功，订单["+resp.get("originalRespMsg")+"]");
				}
			}else{
				renderFail("查询失败,交易系统返回" + resp.get("respMsg"));
			}
		} catch (Exception e) {
			e.printStackTrace();
			renderFail("查询失败，系统发生异常.");
		}
	}
	
	
	
}
